<?php

//kiểm tra những khách hàng có tổng cọc bị lưu sai
include_once '../include/common.php';
$core = new core();

$list_customer_order = $core->db->get_results("SELECT * FROM zen_customer_order");
if($list_customer_order){
    foreach($list_customer_order as $order){
        $data_total_payment = $core->db->query("UPDATE zen_customer_order 
SET customer_order_status = (CASE (SELECT COUNT(id) FROM zen_customer_order_detail zcod WHERE zcod.customer_order_id=".$order->customer_order_id.")
     WHEN (SELECT COUNT(id) FROM zen_customer_order_detail zcod WHERE zcod.customer_order_id=".$order->customer_order_id." AND order_status=0 ) THEN 0
     WHEN (SELECT COUNT(id) FROM zen_customer_order_detail zcod WHERE zcod.customer_order_id=".$order->customer_order_id." AND order_status=1 ) THEN 1
      WHEN (SELECT COUNT(id) FROM zen_customer_order_detail zcod WHERE zcod.customer_order_id=".$order->customer_order_id." AND order_status=2 ) THEN 2
       WHEN (SELECT COUNT(id) FROM zen_customer_order_detail zcod WHERE zcod.customer_order_id=".$order->customer_order_id." AND order_status=3 ) THEN 3
      WHEN (SELECT COUNT(id) FROM zen_customer_order_detail zcod WHERE zcod.customer_order_id=".$order->customer_order_id." AND order_status=4 ) THEN 4
      WHEN (SELECT COUNT(id) FROM zen_customer_order_detail zcod WHERE zcod.customer_order_id=".$order->customer_order_id." AND order_status=5 ) THEN 5
       WHEN (SELECT COUNT(id) FROM zen_customer_order_detail zcod WHERE zcod.customer_order_id=".$order->customer_order_id." AND order_status=6 ) THEN 6
        WHEN (SELECT COUNT(id) FROM zen_customer_order_detail zcod WHERE zcod.customer_order_id=".$order->customer_order_id." AND order_status=7 ) THEN 7
      WHEN (SELECT COUNT(id) FROM zen_customer_order_detail zcod WHERE zcod.customer_order_id=".$order->customer_order_id." AND order_status=8 ) THEN 8
     ELSE 9 END
) WHERE customer_order_id=".$order->customer_order_id);
       
        echo "customer_order_id=".$order->customer_order_id.": ".$data_total_payment."<br/>" ;
    }
    
}
echo "DONE";
?>